package 多线程.线程状态.优先级;

/**
 * 线程优先级（1-10）默认5
 * 1.NORM_PRIORITY 5
 * 2.MIN_PRIORITY 1
 * 3.MAX_PRIORITY 10
 */
public class PriorityTest {
    public static void main(String[] args) {
        System.out.println(
                Thread.currentThread().getName() +
                        "aaa" +
                        Thread.currentThread().getPriority());
        MyPriority m = new MyPriority();
        Thread t1 = new Thread(m);
        Thread t2 = new Thread(m);
        Thread t3 = new Thread(m);
        Thread t4 = new Thread(m);
        Thread t5 = new Thread(m);
        Thread t6 = new Thread(m);

        //在启动之前设置优先级
        t1.setPriority(Thread.MAX_PRIORITY);
        t2.setPriority(Thread.MAX_PRIORITY);
        t3.setPriority(Thread.MAX_PRIORITY);
        t4.setPriority(Thread.MIN_PRIORITY);
        t5.setPriority(Thread.MIN_PRIORITY);
        t6.setPriority(Thread.MIN_PRIORITY);

        t1.start();
        t2.start();
        t3.start();
        t4.start();
        t5.start();
        t6.start();
    }

}

class MyPriority implements Runnable {
    @Override
    public void run() {
        System.out.println(
                Thread.currentThread().getName() +
                        "aaa" +
                        Thread.currentThread().getPriority());

    }
}
